package com.twelve.all.base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * Created by 张龙臣 on 2018/7/27.
 */

public abstract class MyBaseAdapter<T> extends BaseAdapter {

    private Context context;
    private List<T> data;

    public MyBaseAdapter(Context context, List<T> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null)
            convertView = LayoutInflater.from(context).inflate(getResource(),null);
        doOnConvertView(data.get(position),convertView);
        return convertView;
    }

    protected abstract int getResource();

    protected abstract void doOnConvertView(T t, View convertView);
}
